package com.hmall.search.web;

import com.alibaba.fastjson.JSON;
import com.hmall.feign.client.ItemFeign;
import com.hmall.feign.common.dto.PageDTO;
import com.hmall.feign.common.pojo.Item;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService searchService;

    /**
     * 查询
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params) {
        //查询
        return searchService.list(params);
    }

    /**
     * 过滤条件
     * @param params
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters (@RequestBody RequestParams params){
        return searchService.filters(params);
    }
}

